package net.sea.setup.ui.wizard.factory.db.impl;

import net.sea.commons.constants.AppConstants;
import net.sea.commons.util.StringUtils;
import net.sea.setup.ui.wizard.enums.OpEvent;
import net.sea.setup.ui.wizard.factory.db.DataBase;
import net.sea.setup.ui.wizard.factory.db.IDBType;

/**
 * oracle数据库
 * 
 * @author 华成伍
 *
 */
public class Oracle implements IDBType {

	/**
	 * 默认端口
	 */
	private static final int DEFAULT_PORT = 1521;

	@Override
	public void fillDBInfo(DataBase db) {
		if (db == null) {
			return;
		}
		db.setDbNameTip("SID：");
		if (db.getOpType() != OpEvent.ModifyEvent) {
			db.setPort(DEFAULT_PORT);
		}
		StringBuffer url = new StringBuffer();
		url.append("jdbc:oracle:thin:@")
				.append(StringUtils.isEmpty(db.getHost()) ? "<host>" : db
						.getHost())
				.append(":")
				.append(db.getPort() == null ? DEFAULT_PORT : db.getPort())
				.append(":")
				.append(StringUtils.isEmpty(db.getDbName()) ? "<sid>" : db
						.getDbName());
		db.setUrl(url.toString());
		db.setDriverClass("oracle.jdbc.driver.OracleDriver");
		db.setDefaultDriverJar(AppConstants.SYSTEM_PATH
				+ "/install/lib/jdbc/ojdbc14.jar");
	}
}
